<template>
  <div class="mod-nuaa__tcertificate">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="请输入姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.idCard" placeholder="请输入身份证号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.certificateNo" placeholder="请输入证书编号" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-select v-model="dataForm.categoryId" placeholder="分类">
          <el-option v-for="item in categoryList" :key="item.id" :label="item.categoryName" :value="parseInt(item.id)"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('nuaa:tcertificate:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('nuaa:tcertificate:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="id" label="序号" header-align="center" align="center" width="100"></el-table-column>
      <el-table-column prop="name" label="姓名" header-align="center" align="center" width="100"></el-table-column>
      <el-table-column prop="idCard" label="身份证号" header-align="center" align="center" width="200"></el-table-column>
      <el-table-column prop="certificateNo" label="证书编号" header-align="center" align="center" width="200"></el-table-column>
      <el-table-column prop="categoryName" label="分类" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column prop="createDate" label="创建时间" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column prop="expirationDate" label="过期时间" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column prop="img" label="证书" header-align="center" align="center">
        <template v-slot="scope">
          <img v-if="scope.row.img" :src="scope.row.img" class="avatar" style="width: 50px; height: 50px" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="hasPermission('nuaa:tcertificate:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('nuaa:tcertificate:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./tcertificate-add-or-update.vue";
import baseService from "@/service/baseService";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/nuaa/tcertificate/page",
      getDataListIsPage: true,
      exportURL: "/nuaa/tcertificate/export",
      deleteURL: "/nuaa/tcertificate",
      deleteIsBatch: true,
      dataForm: {
        name: "",
        idCard: "",
        certificateNo: "",
        categoryId: ""
      },
      categoryList: []
    });
    return { ...useView(state), ...toRefs(state) };
  },
  created() {
    baseService.get("/nuaa/tcategory/list").then((response) => {
      this.categoryList = response.data;
    });
  },
  watch: {}
});
</script>
